﻿var nodeIds = ""; //结点ids
var onceOper = 1; //单次循环生成的页面数
var contentIds = ""; //内容ids
var Extraids = "";
var acType = 'PubContent';
var contentTotal = 0;
var listPageCount = 5;
function InitJsData(strnodeids, strOnceOper, strContentids, stracType, strcontentTotal, strExtraids) {
    nodeIds = strnodeids;
    onceOper = strOnceOper;
    contentIds = strContentids;
    acType = stracType;
    contentTotal = strcontentTotal;
    Extraids = strExtraids;
}
function showProcess(blnNodePubFlag, blnContentPubFlag, blnExtraPubFlag) {
    //alert("nodeIds:" + nodeIds + "    onceOper:" + onceOper + "   contentIds:" + contentIds + "  acType:" + acType + "  contentTotal:" + contentTotal);
    var NodePubFlag = blnNodePubFlag;
    var ContentPubFlag = blnContentPubFlag;
    var ExtraPubFlag = blnExtraPubFlag;
    
    if (NodePubFlag) {
        //列表页 对于列表页，单次只循环生成一个页面
        NodePub();
    }
    if (ContentPubFlag) {
        //内容页
        ContentPub();
    }
    if (ExtraPubFlag) {
        //附加发布
        ExtraPub();
    }
//附加发布
function ExtraPub() {
    $("#spaceusedExtraPub").progressBar(1);
    ExtraCount = Extraids.toString().replace(" ", "").split(',').length;
    ExtraArray = Extraids.toString().replace(" ", "").split(',');
    ExtraPostCount = ExtraCount; //回传次数 有几个结点回传几次
    tempExtraIndex = 0; //当前进度
    for (tempPost = 0; tempPost < ExtraPostCount; tempPost++) {
        tempExtras = ExtraArray[tempPost];
        for (i = 1; i <= listPageCount; i++) {
            $.ajax({
                cache:false,
                url: "admin_publish.aspx?AjaxPostBack=true&type=Extra" + "&index="+i+"&countNum=1" + "&Extras=" + tempExtras,
                success: function(msg) {
                    tempExtraIndex += 1;
                    //alert("ExtraOk");
                    $("#spaceusedExtraPub").progressBar(Math.floor(100 * tempExtraIndex / parseInt(ExtraPostCount * listPageCount)));
                },
                error: function(xmlHttpRequest, error) {
                    tempExtraIndex += 1;
                    //alert("Extraerror");
                    $("#spaceusedExtraPub").progressBar(Math.floor(100 * tempExtraIndex / parseInt(ExtraPostCount * listPageCount)));
                }
            });
        }
    }
}
//结点发布
function NodePub() {
    $("#spaceusedNode").progressBar(1);
    nodeCount = nodeIds.toString().replace(" ", "").split(',').length;
    nodeArray = nodeIds.toString().replace(" ", "").split(',');
    nodePostCount = nodeCount; //回传次数 有几个结点回传几次
    tempnodeIndex = 0; //当前进度
    for (tempPost = 0; tempPost < nodePostCount; tempPost++) {
        tempNodes = nodeArray[tempPost];
        for (i = 1; i <= listPageCount; i++) {
            $.ajax({
                cache: false,
                url: "admin_publish.aspx?AjaxPostBack=true&type=node&nodeIds=" + tempNodes + "&index=" + i + "&countNum=1",
                success: function(msg) {
                    tempnodeIndex += 1;
                    $("#spaceusedNode").progressBar(Math.floor(100 * tempnodeIndex / parseInt(nodePostCount * listPageCount)));
                },
                error: function(xmlHttpRequest, error) {
                    tempnodeIndex += 1;
                    $("#spaceusedNode").progressBar(Math.floor(100 * tempnodeIndex / parseInt(nodePostCount * listPageCount)));
                }
            });
        }
    }
}
//内容发布
function ContentPub() {
        $("#spaceusedContent").progressBar(1);
        contentTotal = contentIds.toString().replace(" ", "").split(',').length;
        contentArray = contentIds.toString().replace(" ", "").split(',');
        contentPostCount = contentTotal; //回传次数
        contentPostAjax = 0; //Ajax进度
        for (tempPost = 1; tempPost <= contentPostCount; tempPost++) {
            tempcontents =  contentArray[tempPost - 1];
            $.ajax({
                cache: false,
                url: "admin_publish.aspx?AjaxPostBack=true&type=content&nodeIds=" + nodeIds + "&contentids=" + tempcontents,
                success: function(msg) {
                    ++contentPostAjax;
                    $("#spaceusedContent").progressBar(Math.floor(100 * contentPostAjax / parseInt(contentPostCount)));
                },
                error: function(xmlHttpRequest, error) {
                    ++contentPostAjax;
                    //alert(error);
                    $("#spaceusedContent").progressBar(Math.floor(100 * contentPostAjax / parseInt(contentPostCount)));
                }
            });
        }
    }
}
function  InitlistPageCount(intlistPageCount)
{
    listPageCount = intlistPageCount;
}